﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WStest.Models;

namespace WStest.Controllers
{
    public class ProfileController : Controller
    {

        Service service = new Service();

        //
        // GET: /Profile/

        public ActionResult Index()
        {
            return View();
        }

        //
        // GET: /Profile/Details

        public ActionResult Details()
        {
            return View(service.GetUserByUsername(User.Identity.Name));
        }
        
        //
        // GET: /Profile/Edit/5
 
        public ActionResult Edit(int id)
        {
            return View();
        }

        //
        // POST: /Profile/Edit/5

        [HttpPost]
        public ActionResult Edit(UserView user)
        {
            try
            {
                service.updateProfile(user.Id, user.FirstName, user.SurName, user.Address, user.Zipcode, user.City, user.Country);
                
                return RedirectToAction("Details");
            }
            catch
            {
                return View();
            }
        }

    }
}
